export default {
  watch: {
    projectId: function (newProjectId) {
      this.getEnvParamsPage({pageNum: 1, pageSize: 10, projectId: this.$store.getters.getProjectId});
    },
    envDetails: function (value, newValue) {
      console.log(value, newValue)
      console.log("111111")
    },
    deep: true,
  },
  computed: {
    projectId: function () {
      return this.$store.getters.getProjectId;
    },
  },
  created() {
    this.getEnvParamsPage({pageNum: 1, pageSize: 10, projectId: this.$store.getters.getProjectId});
    this.getEnvList({projectId: this.$store.getters.getProjectId});
  },
  data() {
    return {
      param: {},
      id: 0,
      modalAction: "",
      envParamsName: "",
      input: "",
      ta: 50,
      envParamList: {
        data: {
          list: []
        }

      },
      envDetails: {
        data: {
          value: [{
            "envId": "",
            "envValue": ""
          }
          ]
        }
      },
      envList: {
        data: []
      },
      dialogFormVisible: false,
      projectContent: "",
      title: "添加项目",
      formLabelWidth: "100px",
    };
  },
  methods: {
    getType(row, column) {
      if (row.type === 1) {
        return "String"
      }
    },
    createTimeFormatter(row, column) {
      return this.$dateFomat.timestampToTime(row.createTime * 1000);
    },
    updateTimeFormatter(row, column) {
      return this.$dateFomat.timestampToTime(row.updateTime * 1000);
    },
    getEnvParamsPage(p) {
      this.$envParams.page(p).then((res) => {
        if (res.code == 200) {
          this.envParamList = res;
          console.log(res);
        }
      }).catch((res) => {
        console.log(res);
      });
    },
    getEnvList(p) {
      this.$env.list(p).then((res) => {
        if (res.code == 200) {
          this.envList = res;
          console.log(res);
        }
      }).catch((res) => {
        console.log(res);
      });
    },
    tjxm() {
      this.dialogFormVisible = true
      this.envParamsName = ""
      this.envDetails.data.value = [{"envId": "", "envValue": ""}]
      this.modalAction = "add";
      this.title = "添加环境参数";
    },
    cz() {
      this.input = "";
    },
    dj() {
      this.param = {
        "name": this.envParamsName,
        "projectId": this.$store.getters.getProjectId,
        "type": 1,
        "value": this.envDetails.data.value
      }
      this.dialogFormVisible = false
      if (this.modalAction === 'add') {
        this.$envParams.envParamsAdd(this.param).then((res) => {
          if (res.code == 200) {
            this.getEnvParamsPage({pageNum: 1, pageSize: 10, projectId: this.$store.getters.getProjectId});
            console.log(res);
          }
        }).catch((res) => {
          console.log(res);
        });
      } else if (this.modalAction === 'edit') {
        this.param.id = this.id
        console.log(this.param)
        this.$envParams.envParamsUpdate(this.param).then((res) => {
          if (res.code == 200) {
            this.getEnvParamsPage({pageNum: 1, pageSize: 10, projectId: this.$store.getters.getProjectId});
            console.log(res);
          }
        }).catch((res) => {
          console.log(res);
        });
      }
    },
    handleEdit(index, value) {
      this.envParamsName = value.name
      this.dialogFormVisible = true;
      this.modalAction = "edit";
      this.title = "修改环境参数";
      this.id = this.envParamList.data.list[index].id
      this.envDetails.data.value = this.envParamList.data.list[index].value
    },
    handleSizeChange(val) {
      this.getEnvParamsPage({
        pageNum: this.envParamList.data.pageNum,
        pageSize: val,
        projectId: this.$store.getters.getProjectId
      });
    },
    handleCurrentChange(val) {
      this.getEnvParamsPage({
        pageNum: val,
        pageSize: this.envParamList.data.pageSize,
        projectId: this.$store.getters.getProjectId
      });
    },
    handleDelete(index) {
      let id = this.envParamList.data.list[index].id;
      this.$env
        .envDelete({id: id})
        .then((res) => {
          this.$message.success(res.message);
          this.getEnvParamsPage({
            pageNum: this.envParamList.data.pageNum,
            pageSize: this.envParamList.data.pageSize,
            projectId: this.$store.getters.getProjectId
          });
        })
        .catch((res) => {
          this.$message.error(res.message);
        });
    },
    envParamsHandleDelete(index, rows) {
      console.log(rows);
      rows.splice(index, 1);
      if (this.envDetails.data.value.length<1){
        this.envDetails.data.value.push({envId: "",envValue: ""})
      }
    },
    handleAdd() {
      this.envDetails.data.value.push({
        "envId": "",
        "envValue": ""
      });
    },
    inputChangedF(index, value) {
      console.log(index, value);
    },
    checkInput() {
      if (this.$refs.input.value === "") {
        this.$refs.input.$el.style.borderColor = 'red'; // 高亮提示
        this.$refs.input.$el.placeholder = '请输入内容'; // 输入框内文案提示
      } else {
        this.$refs.input.$el.style.borderColor = ''; // 取消高亮提示
        this.$refs.input.$el.placeholder = ''; // 清除输入框内文案提示
      }
    }

  },

}
